<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use EasyWeChat\Factory;

class IndexController extends Controller
{
    private $app;
    public function __construct()
    {
        $config = [
            'app_id' => 'wx498cb645c5729799',
            'secret' => '2fbe95a65e31abf5c1608900c13640a6',
            'response_type' => 'array',
        ];

        $this->app = Factory::miniProgram($config);
    }

    public function code(Request $request)
    {
        $data = $this->app->auth->session($request['code']);
        return response_json($data);
    }
}
